package org.dandelion.papercheck.entity;

import lombok.Data;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

@Entity
@EntityListeners(AuditingEntityListener.class)
@Data
public class User {
    @Id
    @CreatedBy
    private Long id;

    @JoinColumn(nullable = false)
    private String username;
    @JoinColumn(nullable = false)
    private String password;
    @JoinColumn(nullable = false)
    private Timestamp registerTime;
    private String phone = "";
    private String email = "";
    @JoinColumn(nullable = false)
    private Boolean isVip = false;
    @JoinColumn(nullable = false)
    private Boolean isAdmin = false;

    @OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
    private List<Article> articles = new ArrayList<>();

    @OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
    private List<History> histories = new ArrayList<>();
}
